<template>
  <div class="product-list">
    <h2>商品列表</h2>
    <div class="product" v-for="product in products" :key="product.id">
      <span>{{ product.name }} - ¥{{ product.price }}</span>
      <button @click="addToCart(product)">添加到购物车</button>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'

export default {
  data() {
    return {
      products: [
        { id: 1, name: '手机', price: 1000 },
        { id: 2, name: '电脑', price: 2000 },
        { id: 3, name: '键盘', price: 200 }
      ]
    }
  },
  methods: {
    ...mapActions(['addItem']),
    
    addToCart(product) {
      this.addItem(product)
    }
  }
}
</script>

<style>
.product {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #eee;
}
</style>